/**
 *  @file SDLEnemyShip.cpp
 *
 *  @date 24-nov-2009
 *  @author Ives van der Flaas
 */

#include "SDLEnemyShip.h"
#include "SDLImageRepresentation.h"
#include "SDLKeyboardController.h"
#include "SDLBullet.h"
#include "SDLSprayingBullet.h"
#include "SDLAudioManager.h"
#include "linearController.h"
#include "shipDescr.h"

namespace si_sdl
{

SDLEnemyShip::SDLEnemyShip(
		si::Vector2 startPosition,
		std::tr1::shared_ptr<si::Representation> rep,
		si::ShipDescr descriptor):
	EnemyShip(startPosition,descriptor)
{
	fRepresentation = rep;
	///TODO: Get this in the enemyship ctor!
}

SDLEnemyShip::~SDLEnemyShip()
{
	// TODO Auto-generated destructor stub
}

std::tr1::shared_ptr<si::Projectile> SDLEnemyShip::newBullet()
{
	// build a new bullet and place it at the tip of the spacecraft.
	if(fProjectileType == si::BULLET)
	{
		return std::tr1::shared_ptr<si::Projectile>(
										new SDLBullet(
												si::Vector2(
														fController->getPosition().getX() + fVirtualSize.getX()/2,
														fController->getPosition().getY() - fVirtualSize.getY()),
														si::DIR_DOWN));
	}
	else if(fProjectileType == si::SPRAYINGBULLET)
	{
		return std::tr1::shared_ptr<si::Projectile>(
										new SDLSprayingBullet(
												si::Vector2(
														fController->getPosition().getX() + fVirtualSize.getX()/2,
														fController->getPosition().getY() - fVirtualSize.getY()),
														si::DIR_DOWN));
	}

	return std::tr1::shared_ptr<si::Projectile>(static_cast<si::Projectile*>(0));
}


void SDLEnemyShip::fire()
{
	EnemyShip::fire();

	SDLAudioManager::get().playSound("audio/enemygun.wav", PLAYONCE);
}

void SDLEnemyShip::justDied()
{
	EnemyShip::justDied();
	SDLAudioManager::get().playSound("audio/explodingship.wav", PLAYONCE);
}
}
